
<@c.html>
<div class="panel panel-_default">
    <div class="panel-heading">
        <h1 class="panel-title" style="font-size: 28px;">
            <a href="./listView">
                <i class="glyphicon glyphicon-chevron-left" style="border: 2px solid #1D2939;border-radius: 50px;font-size: 28px;"></i>
            </a>
            数据字典子项
        </h1>
    </div>
    <div class="panel-body">
        <div class="row">
            <form class="form-horizontal" id="form-table">
                <input name="id" type="hidden" value="${id!""}"/>
                        <div class="form-group">
                            <label class="control-label col-sm-3">编码</label>
                            <div class="col-sm-6">
                                    <input class="form-control" type="text" id="code" name="code"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-3">名称</label>
                            <div class="col-sm-6">
                                    <input class="form-control" type="text" id="name" name="name"/>
                            </div>
                        </div>
                        <input type="hidden" id="dicId" name="dicId"/>
            </form>
        </div>
        <div class="row text-center">
            <button class="btn btn-primary" id="btn-save">save</button>
        </div>
    </div>
</div>
</@c.html>
<script type="application/javascript">
    $(function(){
        $('#btn-save').click(function(){
            var params = {};
            $.each($("#form-table").serializeArray(), function(i, data) {
                params[data.name] =  data.value;
            });

            $.ajax({
                type : "post",
                url : '.',
                contentType:"json",
                headers: {"Content-Type":"application/json"},
                data: JSON.stringify(params),
                success:function (result) {
                    console.log(result);
                    window.location.href = './listView';
                },
                error:function(xmlHttpRequest , message,  error){
                    bootbox.alert("error");
                    console.log(message);
                }
            });

            console.log(jsonData);
        });

        <#if id??>
            $.getJSON("./${id}", function(data){
                loadForm($("#form-table"), data);
            });
        </#if>
        function loadForm($form, data){
            for(var name in data){
                if(true === data[name]){
                    $form.find('*[name="' + name + '"]').attr("checked","true");
                }else{
                    $form.find('*[name="' + name + '"]').val(data[name]);
                }
            }
        }
    });
</script>